/* GUI CONVERTED from rcoqty.p (converter v1.75) Tue Apr 10 12:04:53 2001 */
/* rcoqty.p - Release Management Customer Schedules                           */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.5.1.2 $                                                         */
/*V8:ConvertMode=Maintenance                                                  */
/* REVISION: 7.0    LAST MODIFIED: 01/29/92   BY: WUG *F110*                  */
/* REVISION: 7.0    LAST MODIFIED: 03/24/92   BY: WUG *F312*                  */
/* REVISION: 8.6    LAST MODIFIED: 09/20/96   BY: TSI *K005*                  */
/* REVISION: 8.6    LAST MODIFIED: 04/28/97   BY: TCC *K0CH*                  */
/* REVISION: 8.6    LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan           */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown           */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.5.1.2 $    BY: Jean Miller        DATE: 03/22/01 ECO: *P008*      */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* CALCULATES OPEN QTY IN A SCHEDULE AS-OF A DATE */

/*INPUT PARAMETERS*/
define input parameter sod_recid as recid.
define input parameter thrudate as date.
define input parameter sched_netting as logical.
define output parameter open_qty like sod_qty_ord.

/*LOCAL VARIABLES*/
define variable req_schedule as integer initial 3.
define variable cum_net_req as decimal no-undo.
define variable net_req as decimal no-undo.
define variable prior_cum_net_req as decimal no-undo.
define variable ship_cmplt as decimal no-undo.
define variable cum_all_qty as decimal no-undo.

find sod_det no-lock where recid(sod_det) = sod_recid.

if not sod_sched then do:
   open_qty = max(sod_qty_ord - sod_qty_ship,0).
   leave.
end.

find so_mstr where so_nbr = sod_nbr no-lock.

assign
   ship_cmplt = if so_ship_cmplt = 0 then
                   100
                else
                   so_ship_cmplt
   open_qty   = 0.

find sch_mstr where
     sch_type = req_schedule
 and sch_nbr = sod_nbr
 and sch_line = sod_line
 and sch_rlse_id = sod_curr_rlse_id[req_schedule]
no-lock no-error.

if not sched_netting then do:
   if available sch_mstr then do:
      find last schd_det
          where schd_type = sch_type
            and schd_nbr = sch_nbr
            and schd_line = sch_line
            and schd_rlse_id = sch_rlse_id
            and schd_date <= thrudate
      no-lock no-error.
      if available schd_det then do:
         open_qty = max(schd_cum_qty - sod_cum_qty[1],0).
      end.
      else do:
         open_qty = max(sch_pcr_qty - sod_cum_qty[1],0).
      end.
   end.
end.

else do:

   /* Open Quantity Calculation */
   if available sch_mstr then
   for each schd_det
      where schd_type    = sch_type
        and schd_nbr     = sch_nbr
        and schd_line    = sch_line
        and schd_rlse_id = sch_rlse_id
        and schd_date    <= thrudate
   no-lock:

      {rcoqty.i}

      open_qty = open_qty + net_req.

   end.

   if open_qty = 0
      and so_cum_acct
      and available sch_mstr
      and sch_pcs_date <= thrudate
   then
      open_qty = max(sch_pcr_qty - sod_cum_qty[1],0).

end.  /* else do */
